#include<bits/stdc++.h>
using namespace std;
using i64=long long;
bool cmp(pair<int,int> p1,pair<int,int> p2)
{
	return p1.first+p2.second>p1.second+p2.first;
}
int main()
{
	int n;
	cin>>n;
	vector<pair<int,int>> v;
	for(int i=1;i<=n;i++)
	{
		int a,b;
		cin>>a>>b;
		v.push_back({a,b});
	}
	sort(v.begin(),v.end(),cmp);
	/*for(auto x:v)
	{
		cout<<x.first<<' '<<x.second<<'\n';
	}*/
	i64 ans=0;
	for(int i=0;i<v.size()-1;i++)
	{
		ans+=v[i].first;
	}
	ans+=v[n-1].second;
	cout<<ans;
	return 0;
}